AliRTC2.5/Windows/MFC Demo/RtcSample/RtcSample.cpp (112 lines of code) (raw):

// RtcSample.cpp : ����Ӧ�ó��������Ϊ�� // #include "stdafx.h" #include "RtcSample.h" #include "RtcSampleDlg.h" #include <Dbghelp.h> #include <signal.h> #include <time.h> #ifdef _DEBUG #define new DEBUG_NEW #endif void signal_abort_handler(int signal) { time_t nowtime; time(&nowtime); struct tm *pTime = NULL; localtime_s(pTime, &nowtime); char szFile[128] = { 0 }; sprintf_s(szFile, "RtcSample_abort_%4d_%02d_%02d_%02d_%02d_%02d.dmp", pTime->tm_year + 1900, pTime->tm_mon + 1, pTime->tm_mday, pTime->tm_hour, pTime->tm_min, pTime->tm_sec); HANDLE hFile = CreateFileA(szFile, GENERIC_READ | GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); if (hFile != INVALID_HANDLE_VALUE) { MINIDUMP_TYPE flags = (MINIDUMP_TYPE)(MiniDumpWithFullMemory | MiniDumpWithFullMemoryInfo | MiniDumpWithHandleData | MiniDumpWithUnloadedModules | MiniDumpWithThreadInfo); BOOL bOK = MiniDumpWriteDump(GetCurrentProcess(), GetCurrentProcessId(), hFile, flags, 0, NULL, NULL); CloseHandle(hFile); } return; } LONG WINAPI exception_handler(struct _EXCEPTION_POINTERS *pExceptionInfo) { LONG ret = EXCEPTION_CONTINUE_SEARCH; time_t nowtime; time(&nowtime); struct tm *pTime = NULL; localtime_s(pTime, &nowtime); char szFile[128] = { 0 }; sprintf_s(szFile, "RtcSample_exception_%4d_%02d_%02d_%02d_%02d_%02d.dmp", pTime->tm_year + 1900, pTime->tm_mon + 1, pTime->tm_mday, pTime->tm_hour, pTime->tm_min, pTime->tm_sec); HANDLE hFile = CreateFileA(szFile, GENERIC_READ | GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); if (hFile != INVALID_HANDLE_VALUE) { MINIDUMP_EXCEPTION_INFORMATION ExInfo; ExInfo.ThreadId = ::GetCurrentThreadId(); ExInfo.ExceptionPointers = pExceptionInfo; ExInfo.ClientPointers = NULL; MINIDUMP_TYPE flags = (MINIDUMP_TYPE)(MiniDumpWithFullMemory | MiniDumpWithFullMemoryInfo | MiniDumpWithHandleData | MiniDumpWithUnloadedModules | MiniDumpWithThreadInfo); BOOL bOK = MiniDumpWriteDump(GetCurrentProcess(), GetCurrentProcessId(), hFile, flags, &ExInfo, NULL, NULL); ret = EXCEPTION_EXECUTE_HANDLER; CloseHandle(hFile); } return ret; } BOOL DisableSetUnhandledExceptionFilter() { HMODULE hKernel32 = LoadLibrary(_T("kernel32.dll")); if (hKernel32 == NULL) return FALSE; void *pOrgEntry = GetProcAddress(hKernel32, "SetUnhandledExceptionFilter"); if (pOrgEntry == NULL) return FALSE; #ifdef _M_IX86 unsigned char szExecute[] = { 0x33, 0xC0, 0xC2, 0x04, 0x00 }; #elif _M_X64 unsigned char szExecute[] = { 0x33, 0xC0, 0xC3 }; #endif SIZE_T bytesWritten = 0; DWORD dwOldFlag, dwTempFlag; //VirtualProtect(pOrgEntry, sizeof(szExecute), PAGE_READWRITE, &dwOldFlag); BOOL bRet = WriteProcessMemory(GetCurrentProcess(), pOrgEntry, szExecute, sizeof(szExecute), &bytesWritten); //VirtualProtect(pOrgEntry, sizeof(szExecute), dwOldFlag, &dwTempFlag); return bRet; } // CRtcSampleApp BEGIN_MESSAGE_MAP(CRtcSampleApp, CWinApp) ON_COMMAND(ID_HELP, &CWinApp::OnHelp) END_MESSAGE_MAP() // CRtcSampleApp ���� CRtcSampleApp::CRtcSampleApp() { // ֧���������������� m_dwRestartManagerSupportFlags = AFX_RESTART_MANAGER_SUPPORT_RESTART; // TODO: �ڴ˴���ӹ�����룬 // ��������Ҫ�ij�ʼ�������� InitInstance �� } // Ψһ��һ�� CRtcSampleApp ���� CRtcSampleApp theApp; // CRtcSampleApp ��ʼ�� BOOL CRtcSampleApp::InitInstance() { // ���һ�������� Windows XP �ϵ�Ӧ�ó����嵥ָ��Ҫ // ʹ�� ComCtl32.dll �汾 6 ����߰汾�����ÿ��ӻ���ʽ�� //����Ҫ InitCommonControlsEx()�� ���򣬽��޷��������ڡ� INITCOMMONCONTROLSEX InitCtrls; InitCtrls.dwSize = sizeof(InitCtrls); // ��������Ϊ��������Ҫ��Ӧ�ó�����ʹ�õ� // �����ؼ��ࡣ InitCtrls.dwICC = ICC_WIN95_CLASSES; InitCommonControlsEx(&InitCtrls); CWinApp::InitInstance(); //set crash dump handler signal(SIGABRT, signal_abort_handler); _set_abort_behavior(0, _WRITE_ABORT_MSG); SetUnhandledExceptionFilter(exception_handler); DisableSetUnhandledExceptionFilter(); AfxEnableControlContainer(); // ���� shell ���������Է��Ի������ // �κ� shell ����ͼ�ؼ��� shell �б���ͼ�ؼ��� CShellManager *pShellManager = new CShellManager; // ���Windows Native���Ӿ����������Ա��� MFC �ؼ����������� CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerWindows)); // ��׼��ʼ�� // ���δʹ����Щ���ܲ�ϣ����С // ���տ�ִ���ļ��Ĵ�С����Ӧ�Ƴ����� // ����Ҫ���ض���ʼ������ // �������ڴ洢���õ�ע����� // TODO: Ӧ�ʵ��޸ĸ��ַ����� // �����޸�Ϊ��˾����֯�� SetRegistryKey(_T("Ӧ�ó��������ɵı���Ӧ�ó���")); CRtcSampleDlg dlg; m_pMainWnd = &dlg; INT_PTR nResponse = dlg.DoModal(); if (nResponse == IDOK) { // TODO: �ڴ˷��ô����ʱ�� // ��ȷ�������رնԻ���Ĵ��� } else if (nResponse == IDCANCEL) { // TODO: �ڴ˷��ô����ʱ�� // ��ȡ�������رնԻ���Ĵ��� } else if (nResponse == -1) { TRACE(traceAppMsg, 0, "����: �Ի��򴴽�ʧ�ܣ�Ӧ�ó���������ֹ��\n"); TRACE(traceAppMsg, 0, "����: ������ڶԻ�����ʹ�� MFC �ؼ������޷� #define _AFX_NO_MFC_CONTROLS_IN_DIALOGS��\n"); } // ɾ�����洴���� shell �������� if (pShellManager != NULL) { delete pShellManager; } #ifndef _AFXDLL ControlBarCleanUp(); #endif // ���ڶԻ����ѹرգ����Խ����� FALSE �Ա��˳�Ӧ�ó��� // ����������Ӧ�ó������Ϣ�á� return FALSE; }